<?php

namespace App\Http\Middleware;

use Closure;

class AccessMiddleware
{
    public function authorize()
    {
        return false;
    }

    /**
     * Handle an incoming request.
     *
     * @param \Illuminate\Http\Request $request
     * @param \Closure $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $tokenString = (string)$request->header("access-token");
        $app_key = env('ACCESS_TOKEN');
        if (empty($tokenString)) {
            return response()->json(['code' => 0, 'msg' => '请申请access-token秘钥', 'data' => null]);
        }
        if ($app_key != $tokenString) {
            return response()->json(['code' => 0, 'msg' => '请申请access-token秘钥', 'data' => null]);
        }
        return $next($request);
    }
}
